home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #5 & #6
/
Amiga Plus CD - 1995 - No. 5 and 6.iso
/
tex
/
src
/
specialhost
/
specialwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-25
|
34KB
|
1,409 lines
/* *** specialwin.c *** */
#include "specialhost.h"
static struct TextFont *font = NULL;
static struct TextAttr txtAttr;
#include "specialwin.h"
/**------------------*** Icon Data ***------------------**/
static USHORT __chip imageData1[] = {
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x0000, 0x0001,
0x0000, 0x0000, 0x07FE, 0x0001,
0x0100, 0x0000, 0x0402, 0x0001,
0x0380, 0x0000, 0x07FE, 0x0001,
0x0540, 0x0000, 0x0402, 0x0001,
0x0100, 0x0000, 0x01DC, 0x0001,
0x0000, 0x0000, 0x0402, 0x0001,
0x0100, 0x0000, 0x07DA, 0x0001,
0x0100, 0x0000, 0x0400, 0x0001,
0x0100, 0x0000, 0x07DA, 0x0001,
0x0100, 0x00F7, 0x4402, 0x0001,
0x0100, 0x00C0, 0x41DA, 0x0001,
0x0100, 0x0092, 0x4402, 0x0001,
0x0100, 0x00A4, 0xC7FE, 0x0001,
0x011F, 0xF8C9, 0x4402, 0x0001,
0x0115, 0x5892, 0x47FE, 0x00C1,
0x011A, 0xA8A4, 0xC402, 0x0061,
0x1FFF, 0xFFFF, 0xFFFF, 0xFFF1,
0x0100, 0x0000, 0x0000, 0x0061,
0x0100, 0x0000, 0x0000, 0x00C1,
0x0000, 0x0000, 0x0000, 0x0001,
0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF,
/**/
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0x8000, 0x0000, 0x0000, 0x0000,
0x8000, 0x0000, 0x0000, 0x0000,
0x8000, 0x0000, 0x0000, 0x0000,
0x8FFC, 0x0E1C, 0x0000, 0x0000,
0x88C4, 0x0B34, 0x0000, 0x0000,
0x80C0, 0x01E0, 0x0000, 0x0000,
0x80CF, 0xC0C0, 0x7800, 0x0000,
0x80CC, 0x41E0, 0x0000, 0x0000,
0x80CC, 0x0B34, 0x0000, 0x0000,
0x80CF, 0x8E1C, 0x0000, 0x0000,
0x800C, 0x0000, 0x0000, 0x0000,
0x800C, 0x4000, 0x0000, 0x0000,
0x800F, 0xC000, 0x0000, 0x0000,
0x8000, 0x0000, 0x07FE, 0x0000,
0x8100, 0x0000, 0x0402, 0x0000,
0x8380, 0x0000, 0x07FE, 0x0000,
0x8540, 0x0000, 0x0402, 0x0000,
0x8301, 0xC38F, 0x0FFF, 0x8800,
0x8102, 0x2448, 0x9526, 0x4800,
0x8182, 0x0448, 0x17FE, 0x4800,
0x8141, 0xC78F, 0x1427, 0xC800,
0x8120, 0x2408, 0x17FE, 0x4800,
0x8112, 0x24FF, 0xD526, 0x4900,
0x8109, 0xC4CF, 0x4FFE, 0x4F00,
0x8100, 0x0092, 0x4402, 0x0000,
0x8100, 0x00A4, 0xC7FE, 0x0000,
0x811F, 0xF8C9, 0x4402, 0x0000,
0x8115, 0x5892, 0x47FE, 0x00C0,
0x811A, 0xA8A4, 0xC402, 0x0060,
0x9FFF, 0xFFFF, 0xFFFF, 0xFFF0,
0x8100, 0x0000, 0x0000, 0x0060,
0x8100, 0x0000, 0x0000, 0x00C0,
0x8000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
/**/
};
struct Image image1 = {
0, /* LeftEdge */
0, /* TopEdge */
ICON_WIDTH, /* Width */
ICON_HEIGHT, /* Height */
2, /* Depth */
NULL, /* ImageData */
0x3, /* PlanePick */
0x0, /* PlaneOnOff */
0, /* [NextImage] */
};
struct scroll_win {
struct scroll_text *top; /* first viewed line */
struct scroll_text *first_free;
long number; /* number of used lines in buffer */
long displayed; /* number of displayed lines */
};
struct scroll_text {
char *line;
struct scroll_text *next_line;
struct scroll_text *prev_line;
short is_first; /* is first line in buffer */
short is_last; /* is last line in buffer */
};
#ifdef LATTICE
extern long _stack;
extern char * _procname;
extern long _priority;
extern long _BackGroundIO;
extern BPTR _Backstdout;
#endif
struct Library *IFFBase = NULL;
struct GfxBase *GfxBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;
extern struct MsgPort *special_port;
extern IFFFILE ifffile;
extern struct BitMap *bmap;
extern short use_blitter;
extern short invert_bmap;
extern short is_os2;
extern short ECS_chips;
static short use_pubscr = FALSE;
static struct Window *win = NULL;
static UBYTE sig_win;
static struct Window *icon = NULL;
static struct scroll_win swin;
static int display_len;
static int lines_to_show;
static int height_char;
static int width_char;
static int icon_x_pos;
static int icon_y_pos;
static int win_x_pos;
static int win_y_pos;
static int win_width;
static int win_height;
static int win_title_height;
static char copyright[] = "SpecialHost Version "VERSION", last compiled: "__DATE__;
static char PubScreenName[] = "ShowDVI-PubScr";
static struct TagItem pub_window_tags[] = {
{ WA_ScreenTitle, &(copyright[0]) },
{ WA_AutoAdjust, TRUE },
{ WA_PubScreenName, &(PubScreenName[0]) },
{ WA_PubScreenFallBack, TRUE },
{ TAG_DONE, 0L }
};
static void OpenI (void);
static void OpenG (void);
static void OpenLib (void);
static void CloseLib (void);
static void CloseWin (void);
static int get_wb_screen_data (int *BarHeight);
static void CloseTopaz (void);
static void OpenTopaz (void);
static void CloseIcon (void);
static UBYTE OpenIcon (void);
static UBYTE OpenWin (void);
static UBYTE ReOpenAll (int draw_modus, int base_dpi);
static void refresh_draw_modus (int draw_modus, int base_dpi);
static void set_picture_draw_modus (long nr, int *draw_modus, int *base_dpi);
static void DrawWin (void);
static long keys (struct IntuiMessage *msg);
static void getShowDVI (void);
static long WindowMessage (int *draw_modus, int *base_dpi);
static void init_text (void);
static void DisplayText (void);
static void ScrollUp (void);
static void ScrollDown (void);
static FILE *OpenConfigFile (char *name, char *modus);
static void ReadConfig (int *draw_modus, int *base_dpi);
static void SaveConfig (int draw_modus, int base_dpi);
void close_all(void)
{
close_port_bitm();
CloseWin();
CloseIcon();
CloseTopaz();
CloseLib();
if (_Backstdout) {
Close(_Backstdout);
_Backstdout = NULL;
}
}
void Fatal(int nr)
{
long ret;
char *message;
char str[64];
switch (nr) {
case NO_INTUI:
message = "can't open Intuition-Library!";
ret = 20;
break;
case NO_GFX:
message = "can't open Graphics-Library!";
ret = 20;
break;
case LINE_TO_LONG:
message = "line too long!!!";
ret = 20;
break;
case NO_WIN:
message = "can't open window!";
ret = 15;
break;
case NO_ICON:
message = "can't open icon-window!";
ret = 15;
break;
case NO_MEMORY:
message = "not enough memory!";
ret = 15;
break;
case NOT_FIRST:
message = "SpecialHost already running!";
ret = 5;
break;
case NO_PORT:
message = "can't open message-port!";
ret = 10;
break;
case NO_MESSAGE:
message = "signal without message??";
ret = 15;
break;
case NO_MEM:
message = "no memory!";
ret = 10;
break;
case NO_OK_BIT:
message = "expect AC_OK_BITMAP!";
ret = 10;
break;
default:
message = "unknown error!?";
ret = 20;
break;
}
sprintf(str, "Fatal: %s\n", message);
if (_Backstdout) {
Write(_Backstdout, str, strlen(str));
}
else {
if (win != NULL) {
pline(message); /* a little bit hacky!!!! */
Delay(50);
}
}
close_all();
exit(ret);
}
static void OpenI(void)
{
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
if (IntuitionBase==NULL) {
Fatal(NO_INTUI);
}
is_os2 = IntuitionBase->LibNode.lib_Version >= 36L;
}
static void OpenG(void)
{
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
if (GfxBase==NULL) {
Fatal(NO_GFX);
}
if (is_os2) {
ECS_chips = GfxBase->ChipRevBits0;
}
}
static void OpenLib(void)
{
#ifndef LATTICE
int bytes;
#endif
OpenI();
OpenG();
#ifdef LATTICE
image1.ImageData = (USHORT *)&imageData1;
#else
bytes = ICON_HEIGHT * ICON_WIDTH * 2 / 8;
image1.ImageData = AllocMem(bytes, MEMF_CHIP | MEMF_PUBLIC);
if (image1.ImageData == NULL) {
Fatal(NO_MEMORY);
}
memcpy((char *)image1.ImageData, (char *)imageData1, bytes);
#endif
}
static void CloseLib(void)
{
#ifndef LATTICE
if (image1.ImageData) != NULL) {
FreeMem(image1.ImageData, ICON_HEIGHT * ICON_WIDTH * 2 / 8);
}
#endif
if (IFFBase != NULL) CloseLibrary(IFFBase);
if (IntuitionBase != NULL) CloseLibrary((struct Library *)IntuitionBase);
if (GfxBase != NULL) CloseLibrary((struct Library *)GfxBase);
}
static void CloseWin(void)
{
struct Message *msg;
if (win != NULL) {
ClearMenuStrip(win);
win_x_pos = win->LeftEdge;
win_y_pos = win->TopEdge;
win_width = win->Width;
win_height = win->Height;
Forbid();
do {
msg = GetMsg(win->UserPort);
if (msg != NULL) ReplyMsg(msg);
} while (msg != NULL);
ModifyIDCMP(win, 0);
Permit();
CloseWindow(win);
win = NULL;
}
}
static void CloseTopaz(void)
{
if (font != NULL) {
CloseFont(font);
font = NULL;
}
}
static void OpenTopaz(void)
{
txtAttr.ta_Name = (STRPTR)FONTNAME;
txtAttr.ta_YSize = FONTYSIZE;
txtAttr.ta_Style = FONTSTYLE;
txtAttr.ta_Flags = FONTFLAGS;
font = OpenFont(&txtAttr);
}
static int get_wb_screen_data(int *BarHeight)
{
struct Screen hscr;
int res = 0;
res = GetScreenData((char *)&hscr, (long)sizeof(hscr), (long)WBENCHSCREEN, IntuitionBase->ActiveScreen);
if (res) {
*BarHeight = hscr.BarHeight;
}
return (res);
}
/*--------------------------------------------*/
static struct Gadget dragit =
{ 0,0, 0, 0, 0,GADGIMAGE|GADGHIMAGE|GRELWIDTH|GRELHEIGHT,GADGIMMEDIATE,
WDRAGGING, (APTR)&image1, (APTR)&image1,0,0,0,0,0 };
static struct NewWindow NewWI = {
0, 0, 0, 0, 2,0, GADGETDOWN,
SMART_REFRESH | BORDERLESS | NOCAREREFRESH,
NULL, NULL, NULL, NULL, NULL, 0,0,0,0, WBENCHSCREEN
};
static void CloseIcon(void)
{
if (icon != NULL) {
RemoveGadget(icon,&dragit);
icon_x_pos = icon->LeftEdge;
icon_y_pos = icon->TopEdge;
CloseWindow(icon);
icon = NULL;
}
}
static UBYTE OpenIcon(void)
{
dragit.Height = ICON_HEIGHT;
NewWI.Height = ICON_HEIGHT;
NewWI.Width = ICON_WIDTH;
NewWI.LeftEdge = icon_x_pos;
NewWI.TopEdge = icon_y_pos;
if (is_os2 && use_pubscr) {
NewWI.Type = PUBLICSCREEN;
icon = OpenWindowTagList(&NewWI, &(pub_window_tags[0]));
}
else {
icon = OpenWindow(&NewWI);
}
if (icon == NULL) {
Fatal(NO_ICON);
}
if (font != NULL) {
SetFont(icon->RPort, font); /* set all to my font */
}
AddGList(icon,&dragit,0,1,0);
RefreshGadgets(&dragit,icon,0);
SetWindowTitles(icon, (UBYTE *) ~0, &(copyright[0]));
return icon->UserPort->mp_SigBit;
}
/*--------------------------------------------*/
static UBYTE OpenWin(void)
{
struct NewWindow new_win;
struct Screen *scr;
#if 0
if (use_blitter) {
Blitter_Gad.Flags |= SELECTED;
}
else {
Blitter_Gad.Flags &= ~SELECTED;
}
if (invert_bmap) {
Invert_Gad.Flags |= SELECTED;
}
else {
Invert_Gad.Flags &= ~SELECTED;
}
#endif
new_win.LeftEdge = win_x_pos;
new_win.TopEdge = win_y_pos;
new_win.Width = win_width;
new_win.Height = win_height;
new_win.DetailPen = 0;
new_win.BlockPen = 1;
new_win.Title = (STRPTR)WIN_TITLE;
new_win.Flags = WINDOWCLOSE | ACTIVATE | WINDOWSIZING | WINDOWDEPTH |
WINDOWDRAG | /* SMART_REFRESH */ SIMPLE_REFRESH /*| GIMMEZEROZERO*/;
new_win.IDCMPFlags = WIN_IDCMP_FLAGS;
new_win.Type = WBENCHSCREEN;
new_win.FirstGadget = &Blitter_Gad;
new_win.CheckMark = NULL;
new_win.Screen = NULL;
new_win.BitMap = NULL;
new_win.MinWidth = WIN_X_MIN_WIDTH;
new_win.MinHeight = WIN_X_MIN_HEIGHT;
new_win.MaxWidth = WIN_X_MAX_WIDTH;
new_win.MaxHeight = WIN_X_MAX_HEIGHT;
if (is_os2 && use_pubscr) {
scr = LockPubScreen(&(PubScreenName[0]));
if (scr == NULL) {
use_pubscr = FALSE;
pline("Can't find the public-screen \"%s\"!", &(PubScreenName[0]));
}
}
if (is_os2 && use_pubscr) {
new_win.Type = PUBLICSCREEN;
win = OpenWindowTagList(&new_win, &(pub_window_tags[0]));
UnlockPubScreen(NULL, scr);
}
else {
win = OpenWindow(&new_win);
}
if (win == NULL) {
Fatal(NO_WIN);
}
if (font != NULL) {
SetFont(win->RPort, font); /* set all to my font */
}
if (is_os2) {
MenItem[7].Flags |= ITEMENABLED;
if (use_pubscr) {
MenItem[7].Flags |= CHECKED;
}
else {
MenItem[7].Flags &= ~CHECKED;
}
}
else {
MenItem[7].Flags &= ~ITEMENABLED;
}
SetMenuStrip(win, &SpecialMenu[0]);
if (!(is_os2 && use_pubscr)) {
SetWindowTitles(win, (UBYTE *) ~0, &(copyright[0]));
}
return win->UserPort->mp_SigBit;
}
static UBYTE ReOpenAll(int draw_modus, int base_dpi)
{
UBYTE sig = 0;
if (win != NULL) {
CloseWin();
sig = OpenWin();
DrawWin();
refresh_draw_modus(draw_modus, base_dpi);
DisplayText();
}
return sig;
}
static void DrawWin(void)
{
struct RastPort *rp;
long start = START_PRINTING + win_title_height - 10;
if (win == NULL) return;
rp = win->RPort;
/**
Move(rp,2,start);
Draw(rp,win->Width-3,start);
Move(rp,2,start-10);
Draw(rp,win->Width-3,start-10);
**/
SetAPen(rp, 3);
Move(rp,win->BorderLeft,start);
Draw(rp,win->Width - win->BorderLeft - win->BorderRight+1,start);
Move(rp,win->BorderLeft,start-10);
Draw(rp,win->Width - win->BorderLeft - win->BorderRight+1,start-10);
}
static long keys(struct IntuiMessage *msg)
{
ULONG Code, Qualifier;
long ret = 0;
Code = msg->Code;
Qualifier = msg->Qualifier;
if (!(Code & 128)) {
switch (Code) {
case CURSORUP:
ScrollUp();
break;
case CURSORDOWN:
ScrollDown();
break;
case 51: /* c */
if (Qualifier & IEQUALIFIER_CONTROL) {
ret = 10;
}
default:
break;
}
}
return ret;
}
static void getShowDVI(void)
{
struct Process *my_proc;
if ((my_proc = (struct Process *)FindTask("ShowDVI-Task")) != NULL) {
Signal(&(my_proc->pr_Task),SIGBREAKF_CTRL_E); /* screen to front */
}
else {
pline("*** ShowDVI is not active!");
}
}
static long WindowMessage(int *draw_modus, int *base_dpi)
{
struct IntuiMessage *msg;
long gnr;
long ret = 0;
UWORD sel;
UBYTE MenuNum, ItemNum;
struct MenuItem *ItemAdr;
while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)) != NULL) {
switch (msg->Class) {
case CLOSEWINDOW:
ret = 10;
break;
case MENUPICK:
sel = msg->Code;
while (sel != MENUNULL) {
MenuNum = MENUNUM(sel);
ItemNum = ITEMNUM(sel);
switch (MenuNum) {
case 0:
switch (ItemNum) {
case 0: /* about */
pline("----------------------------------------------------");
pline(&(copyright[0]));
pline("Copyright© 90/91 Georg Heßmann. All Rights Reserved.");
pline("----------------------------------------------------");
break;
case 2: /* read cnf */
ReadConfig(draw_modus, base_dpi);
break;
case 3: /* save cnf */
SaveConfig(*draw_modus, *base_dpi);
break;
case 5: /* ShowDVI */
getShowDVI();
break;
case 6: /* icon */
ret = 3;
break;
case 7: /* use pubscreen */
use_pubscr = !use_pubscr;
/* nun wird das Window zugemacht!! Also Message zurueck und *keine* mehr holen!! */
ReplyMsg(&(msg->ExecMessage));
ReOpenAll(*draw_modus, *base_dpi);
return ret; /* wichtig, sonst GURU */
break;
case 9: /* quit */
ret = 10;
break;
}
break;
case 1:
switch (ItemNum) {
case 0: /* memory */
*draw_modus = DRAW_IN_MEM;
break;
case 1: /* file */
*draw_modus = DRAW_FILE;
break;
case 2: /* memory-border */
*draw_modus = DRAW_IN_MEM_B;
break;
case 3: /* file-border */
*draw_modus = DRAW_FILE_B;
break;
case 4: /* border */
*draw_modus = DRAW_BORDER;
break;
case 5: /* rectangle */
*draw_modus = DRAW_RECT;
break;
}
refresh_draw_modus(*draw_modus, *base_dpi);
break;
case 2:
switch (ItemNum) {
case 0: /* invert */
invert_bmap = !invert_bmap;
if (invert_bmap) {
Invert_Gad.Flags |= SELECTED;
pline("Invert b&w bitmap");
}
else {
Invert_Gad.Flags &= ~SELECTED;
pline("Use original b&w bitmap");
}
RefreshGadgets(&Invert_Gad, win, NULL);
break;
case 1: /* blitter */
use_blitter = !use_blitter;
if (use_blitter) {
Blitter_Gad.Flags |= SELECTED;
pline("Use Blitter for b&w scaling (if possible)");
}
else {
Blitter_Gad.Flags &= ~SELECTED;
pline("Use software routine for b&w scaling");
}
RefreshGadgets(&Blitter_Gad, win, NULL);
break;
}
break;
}
ItemAdr = ItemAddress(&SpecialMenu[0], sel);
sel = ItemAdr->NextSelect;
}
break;
case MOUSEBUTTONS:
/* not used */
if (msg->Code == MENUDOWN) {
;
}
else {
if (msg->Code == SELECTDOWN) {
;
}
}
break;
case GADGETUP:
gnr = ((struct Gadget *)(msg->IAddress))->GadgetID;
switch (gnr) {
case NR_TOICON_GAD:
ret = 3;
break;
case NR_SHOW_GAD:
getShowDVI();
break;
case NR_INVERT_GAD:
invert_bmap = !invert_bmap;
if (invert_bmap) {
pline("Invert b&w bitmap");
Invert_Gad.Flags |= SELECTED;
MenItem[INVERTNR].Flags |= CHECKED;
}
else {
pline("Use original b&w bitmap");
Invert_Gad.Flags &= ~SELECTED;
MenItem[INVERTNR].Flags &= ~CHECKED;
}
RefreshGadgets(&Invert_Gad, win, NULL);
break;
case NR_BLITTER_GAD:
use_blitter = !use_blitter;
if (use_blitter) {
pline("Use Blitter for b&w scaling (if possible)");
Blitter_Gad.Flags |= SELECTED;
MenItem[BLITTERNR].Flags |= CHECKED;
}
else {
pline("Use software routine for b&w scaling");
Blitter_Gad.Flags &= ~SELECTED;
MenItem[BLITTERNR].Flags &= ~CHECKED;
}
RefreshGadgets(&Blitter_Gad, win, NULL);
break;
default:
set_picture_draw_modus(gnr, draw_modus, base_dpi);
refresh_draw_modus(*draw_modus, *base_dpi);
break;
}
break;
case NEWSIZE:
case REFRESHWINDOW:
DisplayText();
DrawWin();
refresh_draw_modus(*draw_modus, *base_dpi);
break;
case RAWKEY:
ret = keys(msg);
break;
default:
pline("*** unknown message (%d)\n",msg->Class);
}
ReplyMsg(&(msg->ExecMessage));
}
return ret;
}
static void set_picture_draw_modus(long nr, int *draw_modus, int *base_dpi)
{
switch(nr) {
case NR_MEM_GAD:
*draw_modus = DRAW_IN_MEM;
break;
case NR_FILE_GAD:
*draw_modus = DRAW_FILE;
break;
case NR_MEM_B_GAD:
*draw_modus = DRAW_IN_MEM_B;
break;
case NR_FILE_B_GAD:
*draw_modus = DRAW_FILE_B;
break;
case NR_BORDER_GAD:
*draw_modus = DRAW_BORDER;
break;
case NR_RECT_GAD:
*draw_modus = DRAW_RECT;
break;
case NR_INT_GAD:
*base_dpi = ((struct StringInfo *)(Bdpi_Gad.SpecialInfo))->LongInt;
pline("Set base dpi to %d",*base_dpi);
break;
default:
pline("Unknown Gadget %d!\n",nr);
}
}
static void refresh_draw_modus(int draw_modus, int base_dpi)
{
register struct RastPort *rp;
struct StringInfo *si;
char *iBuf, *iuBuf;
int i;
if (win == NULL) return; /* wird fuers erste ReadConfig gebraucht!!! */
rp = win->RPort;
SetAPen(rp, 3);
for (i=STARTDRAW; i<STARTDRAW+6; i++) {
MenItem[i].Flags &= (~CHECKED);
}
Memory_Gad.Flags &= ~SELECTED;
File_Gad.Flags &= ~SELECTED;
Memory_B_Gad.Flags &= ~SELECTED;
File_B_Gad.Flags &= ~SELECTED;
Border_Gad.Flags &= ~SELECTED;
Rect_Gad.Flags &= ~SELECTED;
Move(rp, 20, START_PRINTING + win_title_height - 10 -2);
switch(draw_modus) {
case DRAW_IN_MEM:
Text(rp,"Transfer picture in memory ",45);
MenItem[STARTDRAW].Flags |= CHECKED;
Memory_Gad.Flags |= SELECTED;
break;
case DRAW_FILE:
Text(rp,"Transfer picture in a file ",45);
MenItem[STARTDRAW+1].Flags |= CHECKED;
File_Gad.Flags |= SELECTED;
break;
case DRAW_IN_MEM_B:
Text(rp,"Transfer picture in memory (draw with border)",45);
MenItem[STARTDRAW+2].Flags |= CHECKED;
Memory_B_Gad.Flags |= SELECTED;
break;
case DRAW_FILE_B:
Text(rp,"Transfer picture in a file (draw with border)",45);
MenItem[STARTDRAW+3].Flags |= CHECKED;
File_B_Gad.Flags |= SELECTED;
break;
case DRAW_BORDER:
Text(rp,"Draw only a border ",45);
MenItem[STARTDRAW+4].Flags |= CHECKED;
Border_Gad.Flags |= SELECTED;
break;
case DRAW_RECT:
Text(rp,"Draw only a filled rectangle ",45);
MenItem[STARTDRAW+5].Flags |= CHECKED;
Rect_Gad.Flags |= SELECTED;
break;
default:
pline("*** Unknown draw mode %d!\n",draw_modus);
break;
}
si = (struct StringInfo *)Bdpi_Gad.SpecialInfo;
iBuf = (char *)si->Buffer;
iuBuf = (char *)si->UndoBuffer;
sprintf(iBuf,"%d",base_dpi);
sprintf(iuBuf,"%d",base_dpi);
si->LongInt = (long)base_dpi;
RefreshGadgets(&Bdpi_Gad, win, NULL);
}
static void init_text (void)
{
struct scroll_text *entry, *entry2, *first_entry;
char *block;
int i;
block = malloc(NR_TEXT_LINES * (LINE_LENGTH+1) * sizeof(char));
if (block == NULL) {
Fatal(NO_MEMORY);
}
memset(block,0,NR_TEXT_LINES * (LINE_LENGTH+1) * sizeof(char));
first_entry = entry2 = NULL;
for (i=0; i<NR_TEXT_LINES; i++) {
if ((entry = malloc(sizeof(struct scroll_text))) == NULL) {
Fatal(NO_MEMORY);
}
entry->is_first = FALSE;
entry->is_last = FALSE;
entry->next_line = entry2;
if (entry2 != NULL) {
entry2->prev_line = entry;
}
entry->line = block;
block += LINE_LENGTH+1;
entry2 = entry;
if (i == 0) {
first_entry = entry;
}
}
first_entry->next_line = entry2;
entry2->prev_line = first_entry;
swin.top = swin.first_free = first_entry;
swin.number = 0;
swin.displayed = 0;
}
void __stdargs pline(char *format,...)
{
volatile va_list argptr;
char maxline[5*LINE_LENGTH+1]; /* about 500 bytes stack! */
char *ptr;
int i, j, len;
va_start(argptr, format);
vsprintf(maxline, format, argptr);
va_end(argptr);
len = strlen(maxline);
if (len >5*LINE_LENGTH+1) {
Fatal(LINE_TO_LONG); /* trashing the stack !! */
}
if (len > display_len) {
strncpy(swin.first_free->line,maxline,display_len);
if (swin.first_free->is_first) {
swin.first_free->is_first = FALSE;
swin.first_free->next_line->is_first = TRUE;
}
if (swin.first_free->prev_line->is_last) {
swin.first_free->prev_line->is_last = FALSE;
swin.first_free->is_last = TRUE;
}
swin.first_free = swin.first_free->next_line;
swin.displayed ++;
if (swin.displayed > lines_to_show) {
swin.top = swin.top->next_line;
swin.displayed --;
}
swin.number++;
DisplayText();
len -= display_len;
ptr = maxline + display_len;
for (i=0; i < len / (display_len-1)+1; i++) {
*swin.first_free->line = '+';
strncpy(swin.first_free->line+1,ptr,display_len-1);
for (j=strlen(swin.first_free->line); j<LINE_LENGTH; j++) {
swin.first_free->line[j] = ' ';
}
swin.first_free->line[LINE_LENGTH] = '\0';
ptr += display_len - 1;
if (swin.first_free->is_first) {
swin.first_free->is_first = FALSE;
swin.first_free->next_line->is_first = TRUE;
}
if (swin.first_free->prev_line->is_last) {
swin.first_free->prev_line->is_last = FALSE;
swin.first_free->is_last = TRUE;
}
swin.first_free = swin.first_free->next_line;
swin.displayed ++;
if (swin.displayed > lines_to_show) {
swin.top = swin.top->next_line;
swin.displayed --;
}
swin.number++;
DisplayText();
}
}
else {
for (i=len; i<LINE_LENGTH; i++) {
maxline[i] = ' ';
}
maxline[LINE_LENGTH] = '\0';
strcpy(swin.first_free->line,maxline);
if (swin.first_free->is_first) {
swin.first_free->is_first = FALSE;
swin.first_free->next_line->is_first = TRUE;
}
if (swin.first_free->prev_line->is_last) {
swin.first_free->prev_line->is_last = FALSE;
swin.first_free->is_last = TRUE;
}
swin.first_free = swin.first_free->next_line;
swin.displayed ++;
if (swin.displayed >= lines_to_show) {
swin.top = swin.top->next_line;
swin.displayed --;
}
swin.number++;
DisplayText();
}
}
static void ScrollUp(void)
{
if (swin.number > swin.displayed && !swin.top->is_first) {
swin.top = swin.top->prev_line;
DisplayText();
}
}
static void ScrollDown(void)
{
struct scroll_text *entry;
int i;
entry = swin.top;
for (entry = swin.top, i=0; !entry->is_last && i<lines_to_show; i++, entry=entry->next_line);
if (i == lines_to_show) {
swin.top = swin.top->next_line;
DisplayText();
}
}
static void DisplayText(void)
{
struct RastPort *rp;
int i, len, more;
long x, y;
struct scroll_text *entry;
long start = START_PRINTING + win_title_height - 10;
if (win == NULL) return; /* ! */
rp = win->RPort;
SetAPen(rp, 1);
display_len = (win->Width - win->BorderLeft - win->BorderRight - 4) / width_char;
lines_to_show = (win->Height - win->BorderBottom - start - 3) / height_char;
more = lines_to_show - swin.displayed;
if (more >= 0) {
if (swin.displayed + more > swin.number) {
more = swin.number - swin.displayed;
}
for (i=0; i<more && !swin.top->is_first; i++) {
swin.top = swin.top->prev_line;
}
swin.displayed += more;
}
else {
for (i=0; i>more && !swin.top->is_last; i--) {
swin.top = swin.top->next_line;
}
swin.displayed += more;
}
x = win->BorderLeft+2;
y = start+height_char;;
entry = swin.top;
for (i=0; i<lines_to_show; i++) {
if (entry == swin.first_free) {
break;
}
len = strlen(entry->line);
if (len > 0) {
if (len > display_len) {
len = display_len;
}
Move(rp,x,y);
Text(rp,entry->line,len);
}
y += height_char;
entry = entry->next_line;
}
if (swin.number > NR_TEXT_LINES) {
swin.number = NR_TEXT_LINES;
}
}
static FILE *OpenConfigFile(char *name, char *modus)
{
register char *ptr;
char path[120], env[120];
FILE *fp = NULL;
int len;
ptr = getenv("TEXCONFIG");
if (ptr == NULL) ptr = "TeX:config";
strcpy(env, ptr);
ptr = strtok(env, ",;");
do {
strcpy(path, ptr);
len = strlen(path);
if (path[len-1] != ':' && path[len-1] != '/') {
path[len] = '/';
path[len+1] = '\0';
}
if (strcmp(path, "./") == 0) path[0] = '\0'; /* ./ is actual directory */
strcat(path, name);
fp = fopen(path, modus);
} while (fp == NULL && (ptr = strtok(NULL, ",;")) != NULL);
return fp;
}
static void ReadConfig(int *draw_modus, int *base_dpi)
{
FILE *f;
struct config_struct cnf;
short old_use_pubscr = use_pubscr;
if ((f = OpenConfigFile("SpecialHost.config", "r")) != NULL) {
if (fread((char*)&cnf, sizeof(cnf), 1, f) == 1) {
if (!(cnf.magic != CONFIG_FILE_MAGIC || cnf.version > CONFIG_FILE_VERSION)) {
use_blitter = cnf.use_blitter;
invert_bmap = cnf.invert_bmap;
*base_dpi = cnf.base_dpi;
*draw_modus = cnf.draw_modus;
icon_x_pos = cnf.icon_x_pos;
icon_y_pos = cnf.icon_y_pos;
win_x_pos = cnf.win_x_pos;
win_y_pos = cnf.win_y_pos;
win_width = cnf.win_width;
win_height = cnf.win_height;
use_pubscr = cnf.use_pubscr;
}
}
fclose(f);
}
if (invert_bmap) {
MenItem[INVERTNR].Flags |= CHECKED;
Invert_Gad.Flags |= SELECTED;
}
else {
MenItem[INVERTNR].Flags &= ~CHECKED;
Invert_Gad.Flags &= ~SELECTED;
}
if (use_blitter) {
MenItem[BLITTERNR].Flags |= CHECKED;
Blitter_Gad.Flags |= SELECTED;
}
else {
MenItem[BLITTERNR].Flags &= ~CHECKED;
Blitter_Gad.Flags &= ~SELECTED;
}
if (win != NULL && use_pubscr != old_use_pubscr) {
sig_win = ReOpenAll(*draw_modus, *base_dpi);
}
refresh_draw_modus(*draw_modus, *base_dpi);
}
static void SaveConfig(int draw_modus, int base_dpi)
{
FILE *f;
struct config_struct cnf;
memset(&cnf, 0, sizeof(cnf));
cnf.magic = CONFIG_FILE_MAGIC;
cnf.version = CONFIG_FILE_VERSION;
cnf.use_blitter = use_blitter;
cnf.invert_bmap = invert_bmap;
cnf.base_dpi = base_dpi;
cnf.draw_modus = draw_modus;
cnf.use_pubscr = use_pubscr;
if (icon != NULL) {
cnf.icon_x_pos = icon->LeftEdge;
cnf.icon_y_pos = icon->TopEdge;
}
else {
cnf.icon_x_pos = icon_x_pos;
cnf.icon_y_pos = icon_y_pos;
}
if (win != NULL) {
cnf.win_x_pos = win->LeftEdge;
cnf.win_y_pos = win->TopEdge;
cnf.win_width = win->Width;
cnf.win_height = win->Height;
}
else {
cnf.win_x_pos = win_x_pos;
cnf.win_y_pos = win_y_pos;
cnf.win_width = win_width;
cnf.win_height = win_height;
}
f = OpenConfigFile("SpecialHost.config", "w");
if (f == NULL) {
pline("*** Can't save configuration!");
}
if (fwrite((char *)&cnf, sizeof(cnf), 1, f) != 1) {
fclose(f);
pline("*** Can't save configuration!");
return;
}
fclose(f);
}
void main(int argc, char *argv[])
{
UBYTE sig_icon = 0;
ULONG sig_mask, sig_mask_win, sig_mask_icon, sig_ret, sig_port;
long ret = 0;
int draw_modus, base_dpi;
int is_icon;
long old_mics = 0, old_sec = 0;
ifffile = NULL;
bmap = NULL;
is_icon = FALSE;
icon = NULL;
win = NULL;
win_x_pos = WIN_X_KOO;
win_y_pos = WIN_Y_KOO;
win_width = WIN_WIDTH;
win_height = WIN_HEIGHT;
icon_x_pos = ICON_LEFT_EDGE;
icon_y_pos = ICON_TOP_EDGE;
base_dpi = 100; /* 100 pixel per inch is the default! */
draw_modus = DRAW_BORDER; /* draw only a border is the default! */
init_text();
display_len = 55; /* Vorabdefinitionen, die passen schon, bis generauere Infos da sind */
lines_to_show = 7;
height_char = HEIGHT_CHAR; /* depents on used font */
width_char = WIDTH_CHAR;
pline(&(copyright[0])); /* geht ins nicht vorhandene Fenster */
swin.top->is_first = TRUE; /* important! Initialisation after first pline */
swin.top->is_last = TRUE; /* ^^^^^^^^^^ */
pline("Copyright© 90/91 Georg Heßmann. All Rights Reserved.");
pline("");
if (FindPort(SPECIAL_PORT) != NULL) {
Fatal(NOT_FIRST);
}
ReadConfig(&draw_modus, &base_dpi);
OpenLib();
OpenTopaz();
if (!get_wb_screen_data(&win_title_height)) {
win_title_height = 10;
}
if (win_title_height != 10) {
short help = win_title_height - 10;
Memory_Gad.TopEdge += help;
File_Gad.TopEdge += help;
Memory_B_Gad.TopEdge+= help;
File_B_Gad.TopEdge += help;
Border_Gad.TopEdge += help;
Rect_Gad.TopEdge += help;
Bdpi_Gad.TopEdge += help;
toIcon_Gad.TopEdge += help;
Show_Gad.TopEdge += help;
Invert_Gad.TopEdge += help;
Blitter_Gad.TopEdge += help;
}
sig_win = OpenWin();
DrawWin();
install_special_port(&special_port);
sig_port = 1 << special_port->mp_SigBit;
refresh_draw_modus(draw_modus, base_dpi);
pline("Use blitter: %s, Invert bitmap: %s",
(use_blitter) ? "on" : "off", (invert_bmap) ? "on" : "off");
pline("First choose the draw mode and the base dpi...");
/* now no IO!! (endcli closes the shell-window) */
if (_Backstdout) {
/* close _Backstdout only after init_text() !! */
Close(_Backstdout);
_Backstdout = NULL;
}
fclose(stderr);
do {
if (is_icon) {
sig_mask_icon = 1 << sig_icon;
sig_mask_win = 0L;
}
else {
sig_mask_icon = 0L;
sig_mask_win = 1 << sig_win;
}
sig_mask = sig_mask_win | sig_mask_icon | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E | sig_port;
sig_ret = Wait(sig_mask);
if (sig_ret & SIGBREAKF_CTRL_E) {
/* Nachfrage von ShowDVI, ob man denn von dem PubScr verschwinden moege... */
if (is_os2 && use_pubscr) {
use_pubscr = FALSE;
ReOpenAll(draw_modus, base_dpi);
}
}
/* *** Intui Message *** */
if (!is_icon && (sig_ret & sig_mask_win)) {
ret = WindowMessage(&draw_modus, &base_dpi);
if (ret == 3) {
is_icon = TRUE;
ret = 0;
/* uebernehme den Wert, der derzeit eingetragen ist */
base_dpi = ((struct StringInfo *)(Bdpi_Gad.SpecialInfo))->LongInt;
CloseWin();
sig_icon = OpenIcon();
}
}
if (is_icon && (sig_ret & sig_mask_icon)) {
struct IntuiMessage *imess;
while (is_icon && ((imess = (struct IntuiMessage *)GetMsg(icon->UserPort)) != NULL)) {
if (DoubleClick(old_sec, old_mics, imess->Seconds, imess->Micros)) {
ReplyMsg(&(imess->ExecMessage));
while((imess = (struct IntuiMessage *)GetMsg(icon->UserPort)) != NULL) {
ReplyMsg(&(imess->ExecMessage)); /* clear message port */
}
is_icon = FALSE;
CloseIcon();
sig_win = OpenWin();
DrawWin();
refresh_draw_modus(draw_modus, base_dpi);
DisplayText();
}
else {
old_sec = imess->Seconds;
old_mics = imess->Micros;
ReplyMsg(&(imess->ExecMessage));
}
}
}
/* *** Message from DVI-driver *** */
if (sig_ret & sig_port) {
/* Uebernehme den Wert aus dem Gadget... */
base_dpi = ((struct StringInfo *)(Bdpi_Gad.SpecialInfo))->LongInt;
ret = work_with_special(draw_modus, base_dpi); /* in file SpecialHost.c */
}
} while (ret == 0 && !(sig_ret & SIGBREAKF_CTRL_C));
close_all();
}